﻿using AccompanyCabinet.Common;
using AccompanyCabinet.Helper;
using AccompanyCabinet.Interface;
using AccompanyCabinet.Model;
using AccompanyCabinet.Provider;
using Google.Protobuf;
using Newtonsoft.Json;
using SocketCmd;
using SocketCS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using ZXing;

namespace AccompanyCabinet.Front
{
    public partial class index : Form
    {
        DataTable LocalDt = new DataTable();
        public index()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }
        #region 视频播放相关
        /// <summary>
        /// 公共实例对象
        /// </summary>
        private IMessageProvider _MessageProvider;
        private IWMPMangerProvider _WMPMangerProvider;
        private SignalrRealService _SignalrRealService;
        private VideoHelper _VideoHelper;


        /// <summary>
        /// 加载视频相关配置项
        /// </summary>
        private void LoadVideoConfiguration()
        {
            string[] localCacheFiles = FileHandler.GetLocalCacheFileList();
            //公共实例初始化
            _MessageProvider = new CustomeMessageProvider(this);
            _WMPMangerProvider = new WMPManager(this.wmp, localCacheFiles, _MessageProvider);
            _VideoHelper = new VideoHelper(_MessageProvider);
            FileHandler._MessageProvider = _MessageProvider;
            //配置WMP
            wmp.uiMode = "none";
            wmp.fullScreen = false;
            wmp.settings.setMode("loop", true);
            //配置项目检查
            string message;
            if (!_VideoHelper.IsConfig(out message))
            {
                _MessageProvider.Show(message);
                return;
            }

            //signalr
            _SignalrRealService = new SignalrRealService(_MessageProvider, _WMPMangerProvider, VideoHelper.SignalrServerAddress);
            _SignalrRealService.ServerFileUpdatedEventHander += (s,e)=>
            {
                _WMPMangerProvider.ActionManager(WMPActionType.Stop);
                this.Invoke(new Action(() =>
                {
                    _VideoHelper.TryUpdate(this, () => {
                        string[] files = FileHandler.GetLocalCacheFileList();
                        _WMPMangerProvider.ReloadPlayList(files);
                        _WMPMangerProvider.ActionManager(WMPActionType.Play);
                    });
                }));
            };
            _SignalrRealService.InitSignalRConnection();

            //更新视频
            _VideoHelper.TryUpdate(this, () =>
            {
                localCacheFiles = FileHandler.GetLocalCacheFileList();
                _WMPMangerProvider.ReloadPlayList(localCacheFiles);
                _WMPMangerProvider.ActionManager(WMPActionType.Play);
            });
        }
        #endregion

        /// <summary>
        /// 大中小箱子剩余个数
        /// </summary>
        int bigCount = 0, midCount = 0, smallCount = 0;
        /// <summary>
        /// 设备唯一标识
        /// </summary>
        string Identity = ConfigurationManager.AppSettings["Identity"].ToString();
        /// <summary>
        /// 箱子id
        /// </summary>
        int BBiId = 0, MBiId = 0, SBiId = 0;
        /// <summary>
        /// 正在使用的箱子id
        /// </summary>
        static int UseBiId = 0;
        /// <summary>
        /// 箱子编号
        /// </summary>
        int BNum = 0, MNum = 0, SNum = 0;
        /// <summary>
        /// 正在使用的箱号
        /// </summary>
        int UseNum = 0;
        /// <summary>
        /// 柜子id
        /// </summary>
        int DId = 0;
        /// <summary>
        /// 箱子类别
        /// </summary>
        string BoxType = "Big";
        /// <summary>
        /// 箱子使用时长
        /// </summary>
        string Duration = "0";
        /// <summary>
        /// 超时价格
        /// </summary>
        decimal OverTimePrice = 0;
        /// <summary>
        /// 付款成功过的状态
        /// </summary>
        public static int paysuc = 0;
        /// <summary>
        /// 存取状态
        /// </summary>
        public static string AccessStatus = "1";
        /// <summary>
        /// 订单编号
        /// </summary>
        public static string OrderNum = "";
        /// <summary>
        /// 订单id
        /// </summary>
        public static string OrderId = "0";
        /// <summary>
        /// 跳转存储页面
        /// </summary>
        public string storage = "1";
        /// <summary>
        /// 第一次不执行P_selectbox_paint  等于2时执行
        /// </summary>
        public int FirstSet = 1;


        XmlDocument xd = new XmlDocument();
        List<CostDetail> costDetails = new List<CostDetail>();
        private void index_Load(object sender, EventArgs e)
        {
            QueryFirst();
            LoadVideoConfiguration();
        }

        /// <summary>
        /// 返回首页加载数据
        /// </summary>
        void QueryFirst()
        {
            p_InputFingerprint.Hide();
            string DeviceType = "One";
            xd.Load("../DeviceData.xml");//加载XML文件
            ///柜子信息
            XmlNodeList xmlNoteList = xd.GetElementsByTagName("Device");
            foreach (XmlElement item in xmlNoteList)
            {
                XmlNodeList xn = item.ChildNodes;
                DeviceType = xn[4].InnerText;
                DId = Convert.ToInt32(xn[0].InnerText);
            }
            ///箱子信息
            XmlNodeList xmlBoxs = xd.GetElementsByTagName("box");
            if (DeviceType == "One")
            {
                string boxType = "Big";//箱子类别
                boxType = xmlBoxs[0].ChildNodes[4].InnerText;
                int count = 0;
                p_TakeBox.Location = new Point(21, 457);
                foreach (XmlElement item in xmlBoxs)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (xn[6].InnerText == "Unuse")
                    {
                        if (count == 0)
                        {
                            MBiId = SBiId = BBiId = Convert.ToInt32(xn[0].InnerText);
                            MNum = SNum = BNum = Convert.ToInt32(xn[1].InnerText);
                        }
                        count++;
                    }
                }
                if (boxType == "Big")
                {
                    p_MidSelectBox.Hide();
                    p_SmallSelectBox.Hide();
                    p_bigSelectBox.Location = new Point(0, 99);
                    lab_BigRemainnum.Text = "剩余（个）：" + count.ToString();
                    bigCount = count;
                }
                if (boxType == "Mid")
                {
                    p_bigSelectBox.Hide();
                    p_SmallSelectBox.Hide();
                    p_MidSelectBox.Location = new Point(0, 99);
                    lab_MidRemainnum.Text = "剩余（个）：" + count.ToString();
                    midCount = count;
                }
                if (boxType == "Small")
                {
                    p_bigSelectBox.Hide();
                    p_MidSelectBox.Hide();
                    p_SmallSelectBox.Location = new Point(0, 99);
                    lab_Smallremainnum.Text = "剩余（个）：" + count.ToString();
                    smallCount = count;
                }
            }
            if (DeviceType == "Two")
            {
                p_MidSelectBox.Hide();
                p_SmallSelectBox.Location = new Point(21, 256);
                foreach (XmlElement item in xmlBoxs)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (xn[6].InnerText == "Unuse" && xn[4].InnerText == "Big")
                    {
                        if (bigCount == 0)
                        {
                            BBiId = Convert.ToInt32(xn[0].InnerText);
                            BNum = Convert.ToInt32(xn[1].InnerText);
                        }
                        bigCount++;
                    }
                    if (xn[6].InnerText == "Unuse" && xn[4].InnerText == "Small")
                    {
                        if (smallCount == 0)
                        {
                            SBiId = Convert.ToInt32(xn[0].InnerText);
                            SNum = Convert.ToInt32(xn[1].InnerText);
                        }
                        smallCount++;
                    }
                }
                lab_BigRemainnum.Text = "剩余（个）：" + bigCount.ToString();
                lab_Smallremainnum.Text = "剩余（个）：" + smallCount.ToString();
            }
            if (DeviceType == "Three")
            {
                foreach (XmlElement item in xmlBoxs)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (xn[6].InnerText == "Unuse" && xn[4].InnerText == "Big")
                    {
                        if (bigCount == 0)
                        {
                            BBiId = Convert.ToInt32(xn[0].InnerText);
                            BNum = Convert.ToInt32(xn[1].InnerText);
                        }
                        bigCount++;
                    }
                    if (xn[6].InnerText == "Unuse" && xn[4].InnerText == "Mid")
                    {
                        if (midCount == 0)
                        {
                            MBiId = Convert.ToInt32(xn[0].InnerText);
                            MNum = Convert.ToInt32(xn[1].InnerText);
                        }
                        midCount++;
                    }
                    if (xn[6].InnerText == "Unuse" && xn[4].InnerText == "Small")
                    {
                        if (smallCount == 0)
                        {
                            SBiId = Convert.ToInt32(xn[0].InnerText);
                            MNum = Convert.ToInt32(xn[1].InnerText);
                        }
                        smallCount++;
                    }
                }
                lab_BigRemainnum.Text = "剩余（个）：" + bigCount.ToString();
                lab_MidRemainnum.Text = "剩余（个）：" + midCount.ToString();
                lab_Smallremainnum.Text = "剩余（个）：" + smallCount.ToString();
            }

            XmlNodeList xmlCosts = xd.GetElementsByTagName("cost");
            foreach (XmlElement item in xmlCosts)
            {
                XmlNodeList xn = item.ChildNodes;
                if (Convert.ToInt32(xn[2].InnerText) > 0)
                {
                    CostDetail cos = new CostDetail();
                    cos.Price = Convert.ToDecimal(xn[1].InnerText);
                    cos.Duration = Convert.ToInt32(xn[2].InnerText);
                    cos.TypeNo = xn[3].InnerText;
                    cos.PriceType = xn[4].InnerText;
                    costDetails.Add(cos);
                }
            }
        }

        /// <summary>
        /// 回调方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static HandleResult SocketReceive(TcpClient sender, byte[] bytes)
        {
            if (bytes.Length <= 6) return HandleResult.Ok;
            var bytelen = BitConverter.ToInt32(bytes.Take(4).ToArray(), 0);
            if (bytes.Length < bytelen) return HandleResult.Ok;
            var reciveBytes = bytes.Skip(4).Take(bytelen - 6).ToArray();
            var header = CmdHeader.Parser.ParseFrom(reciveBytes);
            switch (header.CmdCode)
            {
                case 0xFF01://硬件注册后，上位机返回
                    break;
                case 0xFF02://登录后，上位机返回
                    break;
                case 0xFF03://硬件上报状态后，上位机返回
                    break;
                case 0x0204://开箱子
                    var openBox = OpenBox.Parser.ParseFrom(reciveBytes);
                    var openBoxDto = new OpenBox
                    {
                        CmdCode = 0x0104,
                        Identity = header.OppositeId,
                        OppositeId = header.Identity,
                        BoxNo = openBox.BoxNo,
                        ResultCode = 1,
                        TimeToken = header.TimeToken
                    };
                    SocketHelper.SocketSend(openBoxDto.ToByteArray());
                    break;
                case 0x0205://支付完成
                    var notify = NotifyPayStatus.Parser.ParseFrom(reciveBytes);
                    if (notify.ResultCode == 2)
                    {
                        OrderNum = notify.OrderNo;
                        OrderId = notify.OrderId.ToString();
                        ReturnTime = timeConstant;
                        QRcodeStatus = 2;
                        if (AccessStatus == "1")
                        {
                            paysuc = 1;
                        }
                        if (AccessStatus == "2")
                        {
                            paysuc = 2;
                        }
                        notify.CmdCode = 0x0105;
                        var id = notify.Identity;
                        notify.Identity = notify.OppositeId;
                        notify.OppositeId = id;
                        SocketHelper.SocketSend(notify.ToByteArray());
                        ///更改订单支付状态
                        string url = "TerminalInfo/ProduceOrder";
                        Dictionary<string, string> parameters = new Dictionary<string, string>();
                        parameters.Add("biId", UseBiId.ToString());
                        parameters.Add("burId", notify.OrderId.ToString());
                        parameters.Add("type", AccessStatus);
                        var res = HttpHelper.Post(parameters, url, 10);
                        return HandleResult.Ok;
                    }
                    break;
                case 0x0206://下发广告通知
                    var notifyDto = new CmdHeader
                    {
                        CmdCode = 0x0106,
                        Identity = header.OppositeId,
                        OppositeId = header.Identity,
                        ResultCode = 1,
                        TimeToken = header.TimeToken
                    };
                    SocketHelper.SocketSend(notifyDto.ToByteArray());
                    break;
                case 0x0207://下发更新信息
                    var paramDto = new CmdHeader
                    {
                        CmdCode = 0x0107,
                        Identity = header.OppositeId,
                        OppositeId = header.Identity,
                        ResultCode = 1,
                        TimeToken = header.TimeToken
                    };
                    SocketHelper.SocketSend(paramDto.ToByteArray());
                    break;
                case 0x020C://
                    break;
                case 0xFF0F://
                    break;
            }
            //MessageBox.Show(Encoding.Default.GetString(reciveBytes));
            return HandleResult.Ok;
        }
        /// <summary>
        ///选择首个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_DurationClick1_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[0], durations[0], "N");
        }
        /// <summary>
        ///获取二维码
        /// </summary>
        /// <param name="price"></param>
        void GetQrCode(string price, string duration, string PT)
        {
            lab_WXpayMoney.Text = "￥" + price;
            lab_ZFBpayMoney.Text = "￥" + price;
            if (PT == "N")
            {
                lab_PayDuration.Text = "时长：" + duration + "小时";
            }
            else
            {
                lab_PayDuration.Text = "超出：" + duration + "小时";
            }
            Duration = duration;
            p_SelectPayType.Show();
            p_SelectDuration.Hide();
            QRcodeStatus = 1;
            if (BoxType == "Big")
            {
                WXCallPayOrder(BBiId.ToString(), price, duration, PT);
                ZFBCallPayOrder(BBiId.ToString(), price, duration, PT);
            }

            if (BoxType == "Mid")
            {
                WXCallPayOrder(MBiId.ToString(), price, duration, PT);
                ZFBCallPayOrder(MBiId.ToString(), price, duration, PT);
            }
            if (BoxType == "Small")
            {
                WXCallPayOrder(SBiId.ToString(), price, duration, PT);
                ZFBCallPayOrder(SBiId.ToString(), price, duration, PT);
            }
        }
        /// <summary>
        /// 调用微信支付接口
        /// </summary>
        /// <param name="BiId">箱子id</param>
        void WXCallPayOrder(string BiId, string prices, string duration, string PT)
        {
            string url = "wxPay/payPreOrder";
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("I", "1");
            parameters.Add("D", duration);
            parameters.Add("C", Identity);
            parameters.Add("U", "0");
            parameters.Add("T", "2");
            parameters.Add("B", BiId);
            parameters.Add("DD", DId.ToString());
            parameters.Add("P", prices);
            parameters.Add("PT", PT);
            var res = HttpHelper.Post(parameters, url, 10);
            if (res.status == "OK")
            {
                var data = JsonConvert.DeserializeObject(res.Message);
                Newtonsoft.Json.Linq.JObject jo = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(data.ToString());
                P_WXpay.Image = Image.FromHbitmap(Tool.Tools.GenerateQRCode(jo["QrCode"].ToString()).GetHbitmap());
            }
            else
            {
                MessageBox.Show(res.Message);
            }
            #region 测试代码
            //string url = "http://192.168.0.142:50772/api/wxPay/payPreOrder";
            //var PostData = "{\"I\":[" + 1 + "],\"D\":\"" + duration + "\",\"U\":1,\"C\":\"" + Identity + "\",\"T\":2,\"B\":\"" + BiId + "\"," +
            //    "\"DD\":\"" + DId.ToString() + "\",\"P\":\"" + prices + "\",\"PT\":\"N\"}";
            //var payData = "";
            //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            //request.Method = "POST";
            //request.ContentType = "application/json";
            //request.ContentLength = Encoding.UTF8.GetByteCount(PostData);
            //byte[] byteArray = Encoding.UTF8.GetBytes(PostData);
            //Stream dataStream = request.GetRequestStream();
            //dataStream.Write(byteArray, 0, byteArray.Length);
            //dataStream.Close();
            //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //Stream myResponseStream = response.GetResponseStream();
            //if (myResponseStream != null)
            //{
            //    StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            //    payData = myStreamReader.ReadToEnd();
            //}

            //var data = JsonConvert.DeserializeObject(payData);
            //Newtonsoft.Json.Linq.JObject jo = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(data.ToString());

            //BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE };
            //writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//编码问题
            //writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H);
            //const int codeSizeInPixels = 240;   //设置图片长宽
            //writer.Options.Height = writer.Options.Width = codeSizeInPixels;
            //writer.Options.Margin = 1;//设置边框
            //ZXing.Common.BitMatrix bm = writer.Encode(jo["QrCode"].ToString());
            //Bitmap img = writer.Write(bm);
            //P_WXpay.Image = img; 
            #endregion
        }

        /// <summary>
        /// 调用支付宝支付接口
        /// </summary>
        /// <param name="BiId"> 箱子id</param>
        void ZFBCallPayOrder(string BiId, string prices, string duration, string PT)
        {
            string url = "aliPay/payPreOrder";
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("I", "1");
            parameters.Add("D", duration);
            parameters.Add("C", Identity);
            parameters.Add("U", "0");
            parameters.Add("T", "2");
            parameters.Add("B", BiId);
            parameters.Add("DD", DId.ToString());
            parameters.Add("P", prices);
            parameters.Add("PT", PT);
            var res = HttpHelper.Post(parameters, url, 10);
            if (res.status == "OK")
            {
                var data = JsonConvert.DeserializeObject(res.Message);
                Newtonsoft.Json.Linq.JObject jo = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(data.ToString());
                P_ZFBPay.Image = Image.FromHbitmap(Tool.Tools.GenerateQRCode(jo["QrCode"].ToString()).GetHbitmap());
            }
            else
            {
                MessageBox.Show(res.Message);
            }
        }

        /// <summary>
        /// 选择第二个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_DurationClick2_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[1], durations[1], "N");
        }

        /// <summary>
        /// 选择第三个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_DurationClick3_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[2], durations[2], "N");
        }
        /// <summary>
        /// 选择第四个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_DurationClick4_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[3], durations[3], "N");
        }

        /// <summary>
        /// 选择中箱子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_MidSelectBox_Click(object sender, EventArgs e)
        {
            if (midCount == 0)
            {
                MessageBox.Show("无箱子可用，请稍等");
                return;
            }
            UseNum = MNum;
            UseBiId = MBiId;
            p_SelcetBox.Hide();
            durations = new List<string>();
            prices = new List<string>();
            selectDurationClick("Mid");
        }
        /// <summary>
        /// 选择大箱子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pl_bigBox_Click(object sender, EventArgs e)
        {
            if (bigCount == 0)
            {
                MessageBox.Show("无箱子可用，请稍等");
                return;
            }
            UseNum = BNum;
            UseBiId = BBiId;
            p_SelcetBox.Hide();
            durations = new List<string>();
            prices = new List<string>();
            selectDurationClick("Big");
        }
        /// <summary>
        /// 选择小箱子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_SmallSelectBox_Click(object sender, EventArgs e)
        {
            if (smallCount == 0)
            {
                MessageBox.Show("无箱子可用，请稍等");
                return;
            }
            UseNum = SNum;
            UseBiId = SBiId;
            p_SelcetBox.Hide();
            durations = new List<string>();
            prices = new List<string>();
            selectDurationClick("Small");
        }
        /// <summary>
        /// 返回
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_returnselectbox_Click(object sender, EventArgs e)
        {
            FirstSet = 2;
            p_SelcetBox.Show();
        }
        /// <summary>
        /// 返回选择时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_retunselectduration_Click(object sender, EventArgs e)
        {
            if (flag > 0)
            {
                FirstSet = 2;
                p_SelcetBox.Show();
            }
            ReturnTime = timeConstant;
            QRcodeStatus = 2;
            p_SelectDuration.Show();
        }
        int flag = 0;
        /// <summary>
        /// 选择大箱子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pb_big_Click(object sender, EventArgs e)
        {
            if (bigCount == 0)
            {
                MessageBox.Show("无箱子可用，请稍等");
                return;
            }
            UseNum = BNum;
            UseBiId = BBiId;
            p_SelcetBox.Hide();
            durations = new List<string>();
            prices = new List<string>();
            selectDurationClick("Big");
        }
        /// <summary>
        /// 选择中箱子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_Mid_Click(object sender, EventArgs e)
        {
            if (midCount == 0)
            {
                MessageBox.Show("无箱子可用，请稍等");
                return;
            }
            UseNum = MNum;
            UseBiId = MBiId;
            p_SelcetBox.Hide();
            durations = new List<string>();
            prices = new List<string>();
            selectDurationClick("Mid");
        }
        /// <summary>
        /// 选择小箱子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_Small_Click(object sender, EventArgs e)
        {
            if (smallCount == 0)
            {
                MessageBox.Show("无箱子可用，请稍等");
                return;
            }
            UseNum = SNum;
            UseBiId = SBiId;
            p_SelcetBox.Hide();
            durations = new List<string>();
            prices = new List<string>();
            selectDurationClick("Small");
        }
        /// <summary>
        /// 选择首个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox7_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[0], durations[0], "N");
        }
        /// <summary>
        /// 选择第二个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox6_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[1], durations[1], "N");
        }
        /// <summary>
        /// 选择第三个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox5_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[2], durations[2], "N");
        }
        /// <summary>
        /// 选择第四个时长
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            GetQrCode(prices[3], durations[3], "N");
        }

        /// <summary>
        /// 支付成功后跳转 录指纹 开锁后跳转页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_paysucess_Tick(object sender, EventArgs e)
        {
            if (paysuc == 1)//开锁存物品
            {
                paysuc = 0;
                p_InputFingerprint.Show();
                p_SelectPayType.Hide();
                //if (timer_paysucess != null)
                //    timer_paysucess.Dispose();
            }
            if (paysuc == 2)//超时开锁取物品
            {
                p_SelectPayType.Hide();
                p_InputFingerprint.Hide();
                p_pwdopenbox.Hide();
                paysuc = 0;
                xd.Load("../DeviceData.xml");//加载XML文件
                XmlNodeList xmlNoteList = xd.GetElementsByTagName("box");
                foreach (XmlElement item in xmlNoteList)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (xn[1].InnerText == UseNum.ToString())
                    {
                        OpenLocked(xn[2].InnerText,xn[3].InnerText);
                    }
                }
                    //p_SelectPayType.Hide();
                    //p_pwdopenbox.Hide();
                    //storage = "2";
                    //ReturnTime = 5;
                }
        }


        #region 调指纹
        IntPtr hHandle = new IntPtr();//地址
        private int Repeat = 1;//定义等待超时
        /// <summary>
        /// 录指纹界面重新加载时运行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_InputFingerprint_Paint(object sender, PaintEventArgs e)
        {
            if (AccessStatus == "1")
            {
                if (BoxType == "Big")
                {
                    lab_inputfingerBox.Text = "即将使用" + BNum + "号箱子";
                }
                if (BoxType == "Mid")
                {
                    lab_inputfingerBox.Text = "即将使用" + MNum + "号箱子";
                }
                if (BoxType == "Small")
                {
                    lab_inputfingerBox.Text = "即将使用" + SNum + "号箱子";
                }

                if (OpenDevice() == 0)
                {
                    Thread thread = new Thread(new ThreadStart(ErollFP));
                    thread.Start();
                    thread.IsBackground = true;
                    if (!thread.IsAlive)
                    {
                        Thread.Sleep(100);
                    }
                }
            }

        }
        /// <summary>
        /// 存东西调用
        /// </summary>
        private unsafe void ErollFP()
        {
            int ret = 0;
            UInt32 nDevAddr = 0xffffffff;
            BEIG1:
            if (Repeat == 0)
            {
                return;
            }
            Fingerdll.ZAZEmpty(hHandle, nDevAddr);
            //生成特征1 
            if (GetChar(hHandle, nDevAddr, 1, 1) != 1)
            {
                Thread.Sleep(50);
                goto BEIG1;
                //goto ENDERR;
            }
            Thread.Sleep(100);
            BEIG2:
            if (Repeat == 0)
            {
                return;
            }
            //生成特征2
            if (GetChar(hHandle, nDevAddr, 2, 2) != 1)
            {
                Thread.Sleep(50);
                goto BEIG2;
                //goto ENDERR;
            }
            Thread.Sleep(100);

            ret = Fingerdll.ZAZRegModule(hHandle, nDevAddr);  //合并特征
            if (ret != 0)
            {
                lb_FingerRemark.Text = "指纹录入失败，请重新录入";
                //ShowInfomation("指纹录入失败，请重新录入");
                Thread.Sleep(50);
                goto BEIG1;
                //goto ENDERR;
            }
            else
            {
                //ShowInfomation("合成指纹模板成功");
            }
            Thread.Sleep(100);
            byte[] matchbufA = new byte[1536];
            int[] lenthbuf = new int[1];
            ret = Fingerdll.ZAZUpChar(hHandle, nDevAddr, 1, matchbufA, lenthbuf);
            if (ret != 0)
            {
                lb_FingerRemark.Text = "指纹录入失败，请重新录入";
               // ShowInfomation("指纹录入失败，请重新录入");
                Thread.Sleep(100);
                goto BEIG1;
                //goto ENDERR;
            }
            else
            {
                /////指纹存入本地
                xd.Load("../DeviceData.xml");//加载XML文件
                XmlNodeList xmlNoteList = xd.GetElementsByTagName("box");
                foreach (XmlElement item in xmlNoteList)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (!string.IsNullOrWhiteSpace(xn[7].InnerText))
                    {
                        Byte[] FingerOne = Tool.Tools.StringToHexByteArr(xn[7].InnerText);
                        unsafe
                        {
                            fixed (byte* src1 = matchbufA)
                            fixed (byte* Dst1 = FingerOne)
                            {
                                if (Fingerdll.MatchScorePc(src1, Dst1) >= 50)
                                {
                                    lb_FingerRemark.Text = "已录过指纹，请换个手指";
                                    //ShowInfomation("已录过指纹，请换个手指");
                                    Thread.Sleep(1000);
                                    if (OpenDevice() == 0)
                                    {
                                        Thread thread = new Thread(new ThreadStart(ErollFP));
                                        thread.Start();
                                        thread.IsBackground = true;
                                        if (!thread.IsAlive)
                                        {
                                            Thread.Sleep(100);
                                        }
                                    }
                                    return;
                                }
                            }
                        }
                    }
                }
                foreach (XmlElement item in xmlNoteList)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (xn[1].InnerText == UseNum.ToString())
                    {
                        ///byte[]转string
                        xn[6].InnerText = "Use";
                        xn[7].InnerText = Tool.Tools.ByteArrToHexString(matchbufA);
                        xn[8].InnerText = OrderNum;
                        xn[9].InnerText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        xn[10].InnerText = Duration;
                        xn[11].InnerText = OverTimePrice.ToString();
                        xn[12].InnerText = OrderId;
                        xd.Save("../DeviceData.xml");
                        lb_FingerRemark.Text = "指纹存储成功，正在开锁";
                        //ShowInfomation("指纹存储成功，正在开锁");
                        CloseDevice();
                        LocalDt.Columns.Add("dpLockId", typeof(int));
                        LocalDt.Columns.Add("dpLockNum", typeof(int));
                        DataRow dr = LocalDt.NewRow();
                        dr["dpLockId"] = xn[2].InnerText;
                        dr["dpLockNum"] = xn[3].InnerText;
                        LocalDt.Rows.Add(dr);
                        new OpenLock().OpenLockAction(LocalDt, 2);
                        LocalDt = new DataTable();
                        p_InputFingerprint.Hide();
                        p_pwdopenbox.Hide();
                        storage = "2";
                        ReturnTime = 5;
                    }
                }
                //saveDeviceParams.FingerOne = matchbufA;   
            }

            //ENDERR:
            //return;

            return;
        }
        /// <summary>
        /// 存东西调用
        /// </summary>
        /// <param name="hHandle"></param>
        /// <param name="nDevAddr"></param>
        /// <param name="buffer"></param>
        /// <param name="Frequency"></param>
        /// <returns></returns>
        int GetChar(IntPtr hHandle, UInt32 nDevAddr, int buffer, int Frequency)
        {
            int ret = 0;
            int iBuffer = buffer;
            ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr);  //获取图象 
            if (ret == 2)
            {
                if (Frequency == 1)
                {
                    lb_FingerRemark.Text = "请您将手指平放在指纹采集器上";
                    //ShowInfomation("请您将手指平放在指纹采集器上");
                }
                else
                {
                    lb_FingerRemark.Text = "请您将相同的手指再次平放在指纹采集器上";
                    //ShowInfomation("请您将相同的手指再次平放在指纹采集器上");
                }
                return 0;
            }
            else if (ret == 0)
            {
                //ShowInfomation("获取图像成功");
            }
            else
            {
                //ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return 0;
            }
            /****************生成特征 *********/
            ret = Fingerdll.ZAZGenChar(hHandle, nDevAddr, iBuffer);  //生成模板
            if (ret != 0)
            {
                //ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return 0;
            }
            else
            {
                lb_FingerRemark.Text = "获取成功";
                //ShowInfomation("获取成功");
            }
            Thread.Sleep(50);
            if (Frequency == 1)
            {
                BEIG2:
                if (ret == 0)
                {
                    ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr);  //获取图象 
                    lb_FingerRemark.Text = "请您将手指移开";
                    //ShowInfomation("请您将手指移开");
                    Thread.Sleep(100);
                    goto BEIG2;
                }
            }
            return 1;
        }
        /// <summary>
        /// 打开USB指纹头
        /// </summary>
        /// <returns>0表示开启成功，1表示开启失败</returns>
        public int OpenDevice()
        {
            byte[] iPwd = new byte[4];
            int ret = Fingerdll.ZAZOpenDeviceEx(ref hHandle, 2, 0, 0, 2, 0);
            if (ret != 0)
            {
                CloseDevice();
                return 1;
            }
            return 0;
        }
        /// <summary>
        /// 关闭USB指纹头
        /// </summary>
        /// <returns>0表示开启成功，1表示开启失败</returns>
        private void CloseDevice()
        {
            Fingerdll.ZAZCloseDeviceEx(hHandle);
        }
        /// <summary>
        /// 暂不用，用它不知道为啥存和取 会乱跳
        /// </summary>
        /// <param name="strInfo"></param>
        private void ShowInfomation(string strInfo)
        {
            if (Repeat != 0)
            {
                if (lb_FingerRemark != null)
                {
                    this.Invoke((EventHandler)(delegate { lb_FingerRemark.Text = strInfo; }));
                }
            }
        }
        #endregion


        private const int DOWNMIS = 30;
        private int DownCount = DOWNMIS;
        private int TakeRepeat = 9999999;//定义等待超时
        /// <summary>
        /// 取东西
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pb_takebox_Click(object sender, EventArgs e)
        {
            TakeRepeat = 9999999;
            AccessStatus = "2";
            p_SelcetBox.Hide();
            p_SelectDuration.Hide();
            p_SelectPayType.Hide();
            p_InputFingerprint.Show();
            lab_inputfingerBox.Text = "";
            if (OpenDevice() == 0)
            {
                Thread thread = new Thread(new ThreadStart(PCmatchfp));
                thread.Start();
                thread.IsBackground = true;
                if (!thread.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }

        /// <summary>
        /// 管理员登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pb_login_Click(object sender, EventArgs e)
        {
            pb_login.Invoke(new Action(() =>
            {
                new Login().Show();
                Hide();
            }));
        }
        /// <summary>
        /// 取东西
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_TakeBox_Click(object sender, EventArgs e)
        {
            TakeRepeat = 9999999;
            AccessStatus = "2";
            p_SelcetBox.Hide();
            p_SelectDuration.Hide();
            p_SelectPayType.Hide();
            p_InputFingerprint.Show();
            lab_inputfingerBox.Text = "";
            if (OpenDevice() == 0)
            {
                Thread thread = new Thread(new ThreadStart(PCmatchfp));
                thread.Start();
                thread.IsBackground = true;
                if (!thread.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }

        /// <summary>
        /// 取物 验证指纹 返回首页按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_retselectbox_Click(object sender, EventArgs e)
        {
            FirstSet = 2;
            p_SelcetBox.Show();
            p_SelectDuration.Show();
            p_SelectPayType.Show();
            p_InputFingerprint.Hide();
        }
        /// <summary>
        ///订单后八位开门
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_pwdopenbox_Click(object sender, EventArgs e)
        {
            lab_orderopenbox.Text = "";
            p_InputFingerprint.Hide();
            p_pwdopenbox.Show();
        }
        /// <summary>
        /// 订单开门的返回按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_retuninput_Click(object sender, EventArgs e)
        {
            p_SelcetBox.Show();
            txt_ordernum.Text = "";
        }
        /// <summary>
        /// 开门按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_oropen_Click(object sender, EventArgs e)
        {
            xd.Load("../DeviceData.xml");//加载XML文件
            XmlNodeList xmlNoteList = xd.GetElementsByTagName("box");
            foreach (XmlElement item in xmlNoteList)
            {
                XmlNodeList xn = item.ChildNodes;
                if (!string.IsNullOrWhiteSpace(xn[8].InnerText))
                {
                    if (xn[8].InnerText.Substring(xn[8].InnerText.Length - 8, 8) == txt_ordernum.Text)
                    {
                        string url = "TerminalInfo/ProduceOrder";
                        Dictionary<string, string> parameters = new Dictionary<string, string>();
                        parameters.Add("biId", xn[0].InnerText);
                        parameters.Add("burId", xn[12].InnerText);
                        parameters.Add("type", AccessStatus);
                        var res = HttpHelper.Post(parameters, url, 10);
                        lab_orderopenbox.Text = "密码正确，正在开门";
                        TimeSpan timeSpan = DateTime.Now - Convert.ToDateTime(xn[9].InnerText).AddHours(Convert.ToInt32(xn[10].InnerText));
                        if (timeSpan.TotalMinutes > 0)
                        {
                            int overtimecount = Convert.ToInt32(timeSpan.TotalMinutes) / 60 > 0 ? Convert.ToInt32(Convert.ToInt32(timeSpan.TotalMinutes) / 60) : 1;
                            if (Convert.ToInt32(timeSpan.TotalMinutes) % 60 > 0) overtimecount++;
                            decimal aa = overtimecount * Convert.ToDecimal(xn[11].InnerText);
                            GetQrCode((overtimecount * Convert.ToDecimal(xn[11].InnerText)).ToString(), overtimecount.ToString(), "O");//调获取二维码界面
                            flag = 1;
                            UseNum =Convert.ToInt32(xn[0].InnerText);
                            return;
                        }
                        if (timeSpan.TotalMinutes <= 0)
                        {
                            OpenLocked(xn[2].InnerText, xn[3].InnerText);
                            return;
                        }
                    }
                }
            }
            lab_orderopenbox.Text = "密码错误，请仔细对比订单号后八位";
        }
        /// <summary>
        /// 开锁
        /// </summary>
        /// <param name="lockId">锁板id</param>
        /// <param name="lockNum">锁板编号</param>
        void OpenLocked(string lockId,string lockNum)
        {
            LocalDt.Columns.Add("dpLockId", typeof(int));
            LocalDt.Columns.Add("dpLockNum", typeof(int));
            DataRow dr = LocalDt.NewRow();
            dr["dpLockId"] = lockId;
            dr["dpLockNum"] = lockNum;
            LocalDt.Rows.Add(dr);
            new OpenLock().OpenLockAction(LocalDt, 1);
            LocalDt = new DataTable();
            AccessStatus = "1";
            storage = "2";///执行5秒后返回首页
            p_pwdopenbox.Hide();///跳过密码开始页面
            ReturnTime = 5;///设定存储页多长时间返回
        }
        /// <summary>
        /// 取东西调用
        /// </summary>
        private void PCmatchfp()
        {
            try
            {
                int ret = 0;
                UInt32 nDevAddr = 0xffffffff;
                BEIG3:
                if (TakeRepeat == 0)
                {
                    return;
                }
                Fingerdll.ZAZEmpty(hHandle, nDevAddr);
                if (TakeGetChar(hHandle, nDevAddr, 1) != 1)
                {
                    Thread.Sleep(50);
                    goto BEIG3;
                }
                byte[] matchbufA = new byte[1536];
                int[] lenthbuf = new int[1];
                ret = Fingerdll.ZAZUpChar(hHandle, nDevAddr, 1, matchbufA, lenthbuf);
                if (ret != 0)
                {
                    Thread.Sleep(50);
                    goto BEIG3;
                    //goto ENDERR;
                }
                xd.Load("../DeviceData.xml");//加载XML文件
                //得到顶层节点列表 
                XmlNodeList xmlNoteList = xd.GetElementsByTagName("box");
                foreach (XmlElement item in xmlNoteList)
                {
                    XmlNodeList xn = item.ChildNodes;
                    if (xn[7].Name == "FingerPrint")
                    {
                        if (!string.IsNullOrWhiteSpace(xn[7].InnerText))
                        {
                            Byte[] FingerOne = Tool.Tools.StringToHexByteArr(xn[7].InnerText);
                            unsafe
                            {
                                fixed (byte* src1 = matchbufA)
                                fixed (byte* Dst1 = FingerOne)
                                {
                                    if (Fingerdll.MatchScorePc(src1, Dst1) >= 50)
                                    {
                                        lb_FingerRemark.Text = "比对成功，正在开锁";
                                        p_InputFingerprint.Hide();///跳到存储页面
                                        TakeRepeat = 0;
                                        CloseDevice();
                                        
                                        //ShowInfomation("比对成功，正在开锁");
                                        UseNum = Convert.ToInt32(xn[1].InnerText);
                                        ///更改订单状态
                                        string url = "TerminalInfo/ProduceOrder";
                                        Dictionary<string, string> parameters = new Dictionary<string, string>();
                                        parameters.Add("biId", xn[0].InnerText);
                                        parameters.Add("burId", xn[12].InnerText);
                                        parameters.Add("type", AccessStatus);
                                        var res = HttpHelper.Post(parameters, url, 10);
                                        ///处理超时  调付款界面
                                        TimeSpan timeSpan = DateTime.Now - Convert.ToDateTime(xn[9].InnerText).AddHours(Convert.ToInt32(xn[10].InnerText));
                                        if (timeSpan.TotalMinutes > 0)
                                        {
                                            int overtimecount = Convert.ToInt32(timeSpan.TotalMinutes)/60> 0 ? Convert.ToInt32(Convert.ToInt32(timeSpan.TotalMinutes)/ 60) : 1;
                                            if (Convert.ToInt32(timeSpan.TotalMinutes) % 60 > 0) overtimecount++;
                                            GetQrCode((overtimecount * Convert.ToDecimal(xn[11].InnerText)).ToString(), overtimecount.ToString(), "O");//调获取二维码界面
                                            flag = 1;
                                            return;
                                        }
                                        if (timeSpan.TotalMinutes <= 0)
                                        {
                                            OpenLocked(xn[2].InnerText, xn[3].InnerText);
                                            return;
                                        }     
                                    }
                                }
                            }
                        }
                    }
                }
                if (TakeRepeat % 4 == 0)
                {
                    lb_FingerRemark.Text = "比对失败，请您移开手指，重新比对";
                    //ShowInfomation("比对失败，请您移开手指，重新比对");
                    Thread.Sleep(1000);
                }
                TakeRepeat--;
                DownCount = DOWNMIS;
                Thread.Sleep(50);
                goto BEIG3;
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
            }
        }
        /// <summary>
        /// 取物品 调用方法
        /// </summary>
        /// <param name="hHandle"></param>
        /// <param name="nDevAddr"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        int TakeGetChar(IntPtr hHandle, UInt32 nDevAddr, int buffer)
        {
            int ret = 0;
            int iBuffer = buffer;
            ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr);  //获取图象 
            if (ret == 2)
            {
                lb_FingerRemark.Text = "请将手指放在采集器上,不要离开";
                //ShowInfomation("请将手指放在采集器上,不要离开");
                return 0;
            }
            else if (ret == 0)
            {
                //ShowInfomation("获取图像成功");
            }
            else
            {
                //ShowInfomation(Fingerdll.ZAZErr2Strt(ret)+"aa");
                return 0;
            }

            /****************生成特征 *********/
            ret = Fingerdll.ZAZGenChar(hHandle, nDevAddr, iBuffer);  //生成模板
            if (ret != 0)
            {
                //ShowInfomation(Fingerdll.ZAZErr2Strt(ret)+"cc");
                return 0;
            }
            else
            {
                lb_FingerRemark.Text = "获取成功，正在比对，请稍等";
                //ShowInfomation("获取成功，正在比对，请稍等");
                return 1;
            }
        }

        /// <summary>
        /// 当选择箱子页面重新加载时执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void p_SelcetBox_Paint(object sender, PaintEventArgs e)
        {
            paysuc = 0;
            flag = 0;
            UseNum = 0;
            AccessStatus = "1";
            QRcodeStatus = 2;
            if (FirstSet == 2)
            {
                bigCount =midCount =smallCount = 0;
                QueryFirst();
            }
        }

        ///ReturnTime二维码存在时间  QRcodeStatus timer是否运行状态  timeConstant时间常量 
        static int ReturnTime = 180, QRcodeStatus = 2, timeConstant = 180;
        /// <summary>
        /// 二维码存在时间方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_QRCode_Tick(object sender, EventArgs e)
        {
            if (QRcodeStatus == 1)
            {
                if (ReturnTime == 0)
                {
                    FirstSet = 2;
                    p_SelcetBox.Show();
                    p_SelectPayType.Hide();
                    ReturnTime = timeConstant;
                }
                else
                {
                    lab_returnTime.Text = ReturnTime.ToString();
                    ReturnTime--;
                }
            }
            if (storage == "2")
            {
                if (ReturnTime == 0)
                {
                    FirstSet = 2;
                    p_SelcetBox.Show();
                    ReturnTime = timeConstant;
                    storage = "1";
                }
                else
                {
                    lab_storagereturn.Text = ReturnTime.ToString();
                    ReturnTime--;
                }
            }
        }




        /// <summary>
        /// 选择时长
        /// </summary>
        List<string> durations = new List<string>();
        List<string> prices = new List<string>();
        void selectDurationClick(string boxType)
        {
            BoxType = boxType;
            int costCount = 0;
            p_SelectDuration.Show();
            for (int i = 0; i < costDetails.Count; i++)
            {
                if (costDetails[i].TypeNo == boxType)
                {
                    durations.Add(costDetails[i].Duration.ToString());
                    prices.Add(costDetails[i].Price.ToString());
                    //durations[costCount] = costDetails[i].Duration.ToString();
                    //prices[costCount] = costDetails[i].Price.ToString();
                    if (costDetails[i].PriceType == "N")
                        costCount++;
                    if (costDetails[i].PriceType == "E")
                    {
                        lab_Durationovertime1.Text = "每超过" + costDetails[i].Duration + "小时加收" + costDetails[i].Price + "元";
                        lab_Durationovertime2.Text = "每超过" + costDetails[i].Duration + "小时加收" + costDetails[i].Price + "元";
                        lab_Durationovertime3.Text = "每超过" + costDetails[i].Duration + "小时加收" + costDetails[i].Price + "元";
                        lab_Durationovertime4.Text = "每超过" + costDetails[i].Duration + "小时加收" + costDetails[i].Price + "元";
                        OverTimePrice = costDetails[i].Price;
                    }
                    if (costDetails[i].PriceType == "E" && costDetails[i].Duration == 0)
                    {
                        lab_Durationovertime1.Text = "每超过1小时加收" + prices[i] + "元";
                        lab_Durationovertime2.Text = "每超过1小时加收" + prices[i] + "元";
                        lab_Durationovertime3.Text = "每超过1小时加收" + prices[i] + "元";
                        lab_Durationovertime4.Text = "每超过1小时加收" + prices[i] + "元";
                        OverTimePrice = Convert.ToDecimal(prices[i]);
                    }
                }
            }
            if (costCount == 0)
            {
                MessageBox.Show("请联系管理员，导入价格");
                FirstSet = 2;
                p_SelcetBox.Show();
                return;
            }
            if (costCount == 1)
            {
                lab_PayDuration.Text = "时长：" + durations[0] + "小时";
                lab_WXpayMoney.Text = "￥" + prices[0];
                lab_ZFBpayMoney.Text = "￥" + prices[0];
                GetQrCode(prices[0], durations[0], "N");
                flag = 1;
            }
            if (costCount == 2)
            {
                lab_Durationcost1.Text = durations[0] + "个小时" + prices[0] + "元";
                lab_Durationcost2.Text = durations[1] + "个小时" + prices[1] + "元";
                p_DurationClick3.Hide();
                p_DurationClick4.Hide();
            }
            if (costCount == 3)
            {
                lab_Durationcost1.Text = durations[0] + "个小时" + prices[0] + "元";
                lab_Durationcost2.Text = durations[1] + "个小时" + prices[1] + "元";
                lab_Durationcost3.Text = durations[2] + "个小时" + prices[2] + "元";
                p_DurationClick4.Hide();
            }
            if (costCount == 4)
            {
                lab_Durationcost1.Text = durations[0] + "个小时" + prices[0] + "元";
                lab_Durationcost2.Text = durations[1] + "个小时" + prices[1] + "元";
                lab_Durationcost3.Text = durations[2] + "个小时" + prices[2] + "元";
                lab_Durationcost4.Text = durations[3] + "个小时" + prices[3] + "元";
            }
        }

        private void label26_Click(object sender, EventArgs e)
        {

        }
    }
}
